import MapComponent from "../components/MapComponent";

export default class MapUtil
{
    static MapAddBall(ballId, row, col, bubbleMap:string[][])
    {
        // 补齐行
        let deltaRow = row - bubbleMap.length + 1;
        for(let i = 0; i < deltaRow; ++i)
        {
            bubbleMap.push([null, null, null, null, null, null, null, null, null, null, null]);
        }
        cc.log( "MapAddBall:" + row + ", " + col);
        bubbleMap[row][col] = ballId;
    }

    static UpdateMapPosition(mapComponent:MapComponent)
    {
        let diameter = 65.4;
        let height = (mapComponent.bubbleMap.length - 1) * diameter * Math.sin(Math.PI/3);
        mapComponent.height = height;

        let deltaY = Math.abs(640 - (mapComponent.position.y + height));

        // 1. 判断是否需要上移 
        // 1.1 y + height < 640
        if(mapComponent.position.y + height < 640)
        {
            let delta = 640 - mapComponent.position.y + height;
            mapComponent.position.y += delta;
        }

        // 1.2 y < 0
        if(mapComponent.position.y < 0)
        {
            let delta = 0 - mapComponent.position.y;
            mapComponent.position.y += delta;
        }

        // 2. 判断是否需要下移
    }
}